package com.xzj.common.feign.interceptor;

import com.xzj.common.core.constants.LogConstants;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.slf4j.MDC;

/**
 * @program: xzj-admin
 * @ClassName: FeignInterceptor
 * @description: 使用feign实现远程调用时，可以通过实现RequestInterceptor接口的apply方法在请求中设置traceID，这样前台的traceID就可以传递到中台，实现前中台的traceId都是同一个，达到串联日志的效果
 * @author: XiaZunJun
 * @create: 2024-08-06 15:19
 */
public class FeignInterceptor implements RequestInterceptor {

    @Override
    public void apply(RequestTemplate requestTemplate) {
        requestTemplate.header(LogConstants.TRACE_ID, MDC.get(LogConstants.TRACE_ID));
    }
}
